/**
 * Created by Administrator on 2017/3/13 0013.
 */

HintScreen = {
    Create: function () {
        var main = {};
        var stage = new PIXI.Container();
        var renderer = new PIXI.CanvasRenderer(256, 256, {antialias: true, transparent: true});
        renderer.view.style.border = "0px dashed black";
        renderer.resize(740, 1136);
        renderer.backgroundColor = 0x000000;


        var container = document.createElement("div");
        container.id = "LayerHintScreen";
        // var container=document.getElementById("LayerHintScreen");
        container.style.position = "absolute";
        document.body.appendChild(container);

        container.appendChild(renderer.view);




        var canStart = false;
        document.addEventListener('HajimeCompleted', setup);

        //程序开始
        function setup(e) {
            // Music["music1"].play();

            // resizeHandler();

            resize();

            //加载页面在正式页面之上

            if (canStart) {
                document.dispatchEvent(new CustomEvent("Start"));
            }

            var hintContent;
            if(screenType=="hor"){
                hintContent=new HintContentHor();
            }
            else{
                hintContent=new HintContentVer();
            }
            // stage.addChild(hintContent);
            // hintContent.alpha=0;

            function SH(bl) {
                if (bl) {
                    // hintContent.alpha=1;
                    stage.addChild(hintContent);
                } else {
                    // hintContent.alpha=0;
                    stage.removeChild(hintContent);
                }
            }

            document.addEventListener("ScreenChange", resizeHandler);

            function resize() {
                var w, h;
                if (screenType == "hor") {
                    w = windowLength1;
                    h = windowLength2;

                    renderer.resize(w*ratio, h*ratio);
                    stage.scale.x = ( h / hintH < w / hintW) ? (w / hintW) : ( h / hintH);
                    stage.scale.y = stage.scale.x;
                    stage.x = (w - hintW * stage.scale.x) * .5;
                    stage.y = (h - hintH * stage.scale.y) * .5;
                }
                else {
                    w = windowLength2;
                    h = windowLength1;
                    renderer.resize(w, h);
                    stage.scale.x = ( h / hintH < w / hintW) ? (w / hintW) : ( h / hintH)*1.2;
                    stage.scale.y = stage.scale.x;
                    stage.x = (w - hintW * stage.scale.x) * .5;
                    stage.y = (h - hintH * stage.scale.y) * .5;
                }
            }

            //页面适配
            function resizeHandler(e) {
                if(e.detail=="hint") {
                    SH(true);
                }
                else{
                    SH(false);
                }
                resize();
            }



        }




        //渲染层
        gameLoop();
        function gameLoop() {
            requestAnimationFrame(gameLoop);
            //Render The Stage
            renderer.render(stage);

        }

        return main;
    }
}
